import { ref } from 'vue';

export function useVanta() {
  // 颜色状态
  const selectedColor: any = ref(localStorage.getItem('themeColor') || '#245282');
  // Vanta 效果状态
  const selectedEffect: any = ref(localStorage.getItem('vantaEffect') || 'waves');

  // 将十六进制颜色字符串转换为数值形式（如 #4cbd89 -> 0x4cbd89）
  const hexToNumber = (hex: unknown): number => {
    if (typeof hex === 'string') {
      // 移除 # 符号并转换为十六进制数字
      return parseInt(hex.replace('#', ''), 16) || 0; 
    }
    // 若传入的不是字符串，返回默认值 0
    return 0; 
  };

  return {
    selectedColor,
    selectedEffect,
    hexToNumber
  };
}
